interface IStorage {
    get:(key:string)=>any
    set:<V>(key:string,value:V)=>void
    remove:(key:string) => void
}


class MyStorage implements IStorage{
    static instance : MyStorage;
    public get(key: string): any {
        if (localStorage.getItem(key) == null){
            return false
        }
        return JSON.parse(localStorage.getItem(key));
    }

    public set<V>(key: string, value: V): void {
        localStorage.setItem(key, JSON.stringify(value));
    }

    public remove(key: string): void {
        localStorage.removeItem(key);
    }

    static getInstance(){
        if (!MyStorage.instance) {
            MyStorage.instance = new MyStorage();
        }
        return MyStorage.instance;
    }
}

const instance = MyStorage.getInstance();

export default instance;